package com.example.springrabbitmq.config;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author pan_jin
 * @Description: $
 * @Date: 2022/8/16 9:58
 * @Version: 1.0.0
 * @Slogan: 梦想还是要有的万一实现了呢
 */
@Configuration
public class MQConfig {
    //配置连接工厂
    @Bean
    public CachingConnectionFactory cachingConnectionFactory(){
        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
        cachingConnectionFactory.setHost("192.168.137.10");
        cachingConnectionFactory.setPort(5672);
        cachingConnectionFactory.setPassword("grape");
        cachingConnectionFactory.setUsername("grape");
        return cachingConnectionFactory;
    }

    @Bean
    public RabbitAdmin rabbitAdmin(){
        //需要传入
        RabbitAdmin rabbitAdmin = new RabbitAdmin(cachingConnectionFactory());
        rabbitAdmin.setAutoStartup(true);
        return rabbitAdmin;
    }

}
